package com.yukh.test.mybatis;

import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

/**
 * mybatis core api test
 * @author kunhua.yu
 *
 */
public class CoreClass {
	
//	@Test
	public void createSessionFactoryNoXml(){
		
	}
	
	@Test
	public void createSessionFactoryFromXml(){
		try {
			Reader reader = Resources.getResourceAsReader("com/yukh/test/mybatis/sqlMapConfig.xml");
			SqlSessionFactory sqlSessionFactroy = new SqlSessionFactoryBuilder().build(reader);
			SqlSession sqlSession = sqlSessionFactroy.openSession();
			StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
			Student stu = studentMapper.selectByStuName("yukh");
//			Student stu = (Student)sqlSession.selectOne("com.yukh.test.mybatis.StudentMapper.selectByStuName", "yukh");
			System.out.println("");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
